Imports System
Imports System.Data.Entity.Migrations

Namespace Migrations
    Public Partial Class TenMigratio
        Inherits DbMigration
    
        Public Overrides Sub Up()
            CreateTable(
                "dbo.DonHangs",
                Function(c) New With
                    {
                        .Id = c.Int(nullable := False, identity := True),
                        .ThoiGian = c.DateTime(nullable := False),
                        .DaThanhToan = c.Boolean(nullable := False),
                        .ThanhTien = c.Int(nullable := False),
                        .Ban_Id = c.Int()
                    }) _
                .PrimaryKey(Function(t) t.Id) _
                .ForeignKey("dbo.Bans", Function(t) t.Ban_Id) _
                .Index(Function(t) t.Ban_Id)
            
            CreateTable(
                "dbo.ChiTietDonHangs",
                Function(c) New With
                    {
                        .Id = c.Int(nullable := False, identity := True),
                        .SoLuong = c.Int(nullable := False),
                        .DonGia = c.Int(nullable := False),
                        .SanPham_Id = c.Int(),
                        .DonHang_Id = c.Int()
                    }) _
                .PrimaryKey(Function(t) t.Id) _
                .ForeignKey("dbo.SanPhams", Function(t) t.SanPham_Id) _
                .ForeignKey("dbo.DonHangs", Function(t) t.DonHang_Id) _
                .Index(Function(t) t.SanPham_Id) _
                .Index(Function(t) t.DonHang_Id)
            
            AddColumn("dbo.Bans", "IdDonHang", Function(c) c.Int(nullable := False))
        End Sub
        
        Public Overrides Sub Down()
            DropIndex("dbo.ChiTietDonHangs", New String() { "DonHang_Id" })
            DropIndex("dbo.ChiTietDonHangs", New String() { "SanPham_Id" })
            DropIndex("dbo.DonHangs", New String() { "Ban_Id" })
            DropForeignKey("dbo.ChiTietDonHangs", "DonHang_Id", "dbo.DonHangs")
            DropForeignKey("dbo.ChiTietDonHangs", "SanPham_Id", "dbo.SanPhams")
            DropForeignKey("dbo.DonHangs", "Ban_Id", "dbo.Bans")
            DropColumn("dbo.Bans", "IdDonHang")
            DropTable("dbo.ChiTietDonHangs")
            DropTable("dbo.DonHangs")
        End Sub
    End Class
End Namespace
